package com.mvp.shq.washer.ui.shop.shopcar;


import com.mvp.shq.washer.entity.result.BaseResult;
import com.mvp.shq.washer.entity.shop.CollectResponse;
import com.mvp.shq.washer.http.BaseObserver;
import com.mvp.shq.washer.utils.SpUtil;
import com.mvp.shq.washer.utils.T;

import java.util.List;

/**
 * Created by westing on 2017/10/09.
 */
public class Presenter extends ShopCarConstract.Presenter {
    @Override
    public void onStart() {

    }

    @Override
    void collectProduct(List<CollectResponse> list) {
        String userId = SpUtil.getUser().getId();
        String token = SpUtil.getToken();
        model.collectProduct(token,userId,list)
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .subscribe(new BaseObserver<String>(view) {
                    @Override
                    protected void onSuccees(BaseResult<String> t) throws Exception {
                        if (t.isError()){
                            T.show(t.getMsg());
                        }else {
                            view.collectProductS();
                        }
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        T.show(e.getMessage());
                        e.printStackTrace();
                    }
                });
    }
}
